package com.jeeplus.modules.flowable.listener;

import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.service.OfficeService;
import com.jeeplus.modules.sys.service.UserService;

@Component("deputyLeaderExecutionListener")
public class DeputyLeaderExecutionListener implements TaskListener {

	private static final long serialVersionUID = -3320464280396293060L;
	
	@Autowired
	private TaskService taskService;
	
	@Autowired
	private OfficeService officeService;
	
	@Autowired
    private UserService userService;

	public void notify(DelegateTask delegateTask) {
		
		

        String eventName = delegateTask.getEventName();

        if ("create".equals(eventName)) {
        	
        	//发起人部门
    		String officeId = (String)delegateTask.getVariable("officeId");
    		Office office=officeService.get(officeId);
    		User user = null;
    		user = office.getDeputyPerson();
    		
    		if(user != null) {
    			taskService.setAssignee(delegateTask.getId(), user.getId());
    		}
        }
        System.err.println("DeputyLeaderExecutionListener");
    }
	
}
